﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    xmlns:local="clr-namespace:Exones.Blend.AssetsManager"
    x:Class="Exones.Blend.AssetsManager.ShellView"
    Title="Blend assets manager" Height="700" Width="700"
    SnapsToDevicePixels="True" UseLayoutRounding="True" WindowStartupLocation="CenterScreen" MinWidth="560" MinHeight="500">

    <Window.Resources>
        <!--<local:AssetFolderTemplateSelector x:Key="FolderTemplateSelector" 
                                           FolderTemplate="{StaticResource FolderTemplate}"
                                           AssetTemplate="{StaticResource AssetTemplate}"
                                           >

        </local:AssetFolderTemplateSelector>-->

        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        
        <HierarchicalDataTemplate x:Key="FolderTemplate"                                  
                                  ItemsSource="{Binding SubFolders}">
            <StackPanel Orientation="Horizontal"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        ToolTip="{Binding Path,FallbackValue={x:Null}}">
                <CheckBox Content=""
                          Visibility="{Binding IsSelectable, Converter={StaticResource BooleanToVisibilityConverter}}"
                          IsChecked="{Binding IsChecked, Mode=TwoWay}"
                          VerticalAlignment="Center"
                          IsThreeState="{Binding IsThreeState}"
                          Margin="3,0,0,0"
                          Padding="0"
                          />
                <TextBlock Text="{Binding Name}"
                       Margin="5,3,5,3" 
                       Padding="0"
                       VerticalAlignment="Center" 
                       TextWrapping="Wrap"/>
                <StackPanel Orientation="Horizontal"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Center"
                        Height="Auto"
                        Visibility="{Binding IsLeaf,Converter={StaticResource BooleanToVisibilityConverter},FallbackValue=False}">
                    <Button x:Name="DeleteAsset" Margin="0,0,3,0" Padding="0" VerticalAlignment="Center"
                            Command="{Binding DeleteAssetCommand}">
                        <Label Padding="0" Margin="3,0,3,0">x</Label>
                    </Button>
                    <Button x:Name="EditAsset" Padding="0" VerticalAlignment="Center" Height="Auto"
                            Command="{Binding EditAssetCommand}"
                            Visibility="Collapsed">
                        <Label Padding="0" Margin="3,0,3,0">~</Label>
                    </Button>
                </StackPanel>
            </StackPanel>
            
        </HierarchicalDataTemplate>       
    </Window.Resources>

    <Grid Margin="10,6,10,10">
        <!--<Label Content="{Binding SelectedBlendFolder.Path, FallbackValue='&lt;Not selected&gt;'}"
               ToolTip="{Binding SelectedBlendFolder.Path, FallbackValue='&lt;Not selected&gt;'}"
               HorizontalAlignment="Left" Margin="31,332,0,0" VerticalAlignment="Top"/>-->              
        
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        
        <StackPanel HorizontalAlignment="Stretch"
                    Grid.Row="0"
                    VerticalAlignment="Top"
                    Height="Auto"
                    DockPanel.Dock="Top">
            <TextBlock FontSize="20" FontWeight="Bold"
                       >
                1. Enter assets group to add
            </TextBlock>
            <TextBlock>Assets group name</TextBlock>
            <TextBox x:Name="UserAssetName" 
                        TabIndex="0"
                        HorizontalAlignment="Stretch"
                        Height="23"
                        TextWrapping="NoWrap" Text="" VerticalAlignment="Stretch"
                        Margin="0,0,0,5"
                        IsEnabled="{local:And {local:Not IsError}, {Binding IsAnyBlendProductInstalled}}">
            </TextBox>
            <TextBlock>Path to assets libraries</TextBlock>
            
            <DockPanel HorizontalAlignment="Stretch">
                <Button x:Name="SelectAssetPath"
                        TabIndex="2"
                        DockPanel.Dock="Right"
                        Content="..."
                        Padding="5,0,5,0"
                        Margin="5,0,0,0"
                        IsEnabled="{local:And {local:Not IsError}, {Binding IsAnyBlendProductInstalled}}"/>
                
                <TextBox x:Name="UserAssetPath"
                            TabIndex="1"
                            HorizontalAlignment="Stretch"
                            Height="23"
                            TextWrapping="NoWrap"
                            Text=""
                            ToolTip="{Binding UserAssetPath}"
                            IsEnabled="{local:And {local:Not IsError}, {Binding IsAnyBlendProductInstalled}}"/>
            </DockPanel>
            
        </StackPanel>

        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            
            <TextBlock FontSize="20" FontWeight="Bold" DockPanel.Dock="Top" Margin="0,10,0,5"
                       Grid.Row="0">
                2. Select platforms and versions to install assets for
            </TextBlock>

            <Grid Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <StackPanel Orientation="Horizontal" Grid.Row="0">
                    <Button x:Name ="ExpandAll" Padding="5,0,5,0" Content="Expand All" HorizontalAlignment="Left" VerticalAlignment="Top"
                        Margin="0,0,5,0" IsEnabled="{local:Not IsError}"/>
                    <Button x:Name ="CollapseAll" Padding="5,0,5,0" Content="Collapse All" HorizontalAlignment="Left" VerticalAlignment="Top"
                        IsEnabled="{local:Not IsError}"/>
                </StackPanel>

                <TreeView HorizontalAlignment="Stretch"
                        Grid.Row="1"
                        Margin="0,5,0,0"
                        TabIndex="3"
                        IsEnabled="{Binding IsAnyBlendProductInstalled}"
                    HorizontalContentAlignment="Stretch"
                    VerticalAlignment="Stretch" 
                    ItemsSource="{Binding InstalledVersions}"
                    ItemTemplate="{StaticResource FolderTemplate}"
                    SelectedItemChanged="TreeView_SelectedItemChanged" MouseDoubleClick="TreeView_MouseDoubleClick" >
                    <TreeView.ItemContainerStyle>
                        <Style TargetType="{x:Type TreeViewItem}">
                            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
                            <Setter Property="HorizontalAlignment" Value="Stretch"/>
                            <Setter Property="Height" Value="Auto"/>
                        </Style>
                    </TreeView.ItemContainerStyle>
                </TreeView>
            </Grid>
            
        </Grid>
        
        <StackPanel Grid.Row="2">
            <TextBlock FontSize="20" FontWeight="Bold" DockPanel.Dock="Top" Margin="0,10,0,5"
                       Grid.Row="0">
                3. Apply assets changes
            </TextBlock>
            <Button x:Name="InstallAssets"
                    FontSize="20"
                    FontWeight="Bold"
                    Content="Apply"
                    HorizontalAlignment="Stretch"
                    Padding="5,10"
                    Margin="0,0,0,0"
                    />
        </StackPanel>
    </Grid>

</Window>